package com.sghd.candy.module.bag.manager;

import com.sghd.common.ramcache.IEntity;
import com.sghd.common.ramcache.anno.Cached;
import com.sghd.common.ramcache.anno.CachedSizes;
import com.sghd.common.ramcache.anno.Persister;
import com.sghd.common.ramcache.anno.Persisters;
import com.sghd.common.ramcache.enhance.Enhance;
import com.sghd.pojo.candy.bag.enums.PropType;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * @author Allen
 * @date 2018/12/11
 */
@Entity
@Table(catalog = "bsdld")
@Cached(size = CachedSizes.DEFAULT, persister = @Persister(Persisters.PRE_10_MINUTE))
public class PlayerBag implements IEntity<Long> {
    /**玩家Id*/
    @Id
    private Long playerId;
    /**钻石*/
    private Long diamond;
    /**游戏币*/
    private Long money;

    public Long getPlayerId() {
        return playerId;
    }

    void setPlayerId(Long playerId) {
        this.playerId = playerId;
    }

    public Long getDiamond() {
        return diamond;
    }

    void setDiamond(Long diamond) {
        this.diamond = diamond;
    }

    public Long getMoney() {
        return money;
    }

    void setMoney(Long money) {
        this.money = money;
    }

    static PlayerBag valueOf(long playerId) {
        PlayerBag playerBag = new PlayerBag();
        playerBag.setPlayerId(playerId);
        playerBag.setMoney(0L);
        playerBag.setDiamond(0L);
        return playerBag;
    }

    @Enhance
    void change(PropType propType, long changNum) {
        switch (propType) {
            case DIAMOND:
                setDiamond(getDiamond() + changNum);
                break;
            case MONEY:
                setMoney(getMoney() + changNum);
                break;
            default:
        }
    }
    @Override
    public Long getId() {
        return this.playerId;
    }
}
